import request from 'umi-request';

export async function getUserList(params) {
  return request('/hr-ssc/api/api-admin/roleAssignment/queryUserList', {
    method: 'post',
    data: {
      name: params.name,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
    requestType: 'form'
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getRolePageList(params) {
  return request('/hr-ssc/api/api-admin/roleAssignment/queryRoleList', {
    method: 'post',
    data: {
      roleName: params.roleName,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
    requestType: 'form'
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}


export async function getOrgGroupPageList(params) {
  return request('/hr-ssc/api/api-admin/roleAssignment/queryOrgGroupList', {
    method: 'post',
    data: {
      groupName: params.groupName,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
    requestType: 'form'
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getUserMsgRoles(userId) {
  return request(`/hr-ssc/api/api-admin/noticeRole/getNoticeRoleByUser?userId=${userId}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getMsgRolesList() {
  return request(`/hr-ssc/api/api-admin/noticeRole/getNoticeRoleListNoPage`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getUserRoles(userId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/getUserRoleInterface`, {
    method: 'post',
    data: {userId: userId},
    requestType: 'form'
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getRolesList() {
  return request(`/hr-ssc/api/api-admin/roleAssignment/queryRoleEntityListInterface`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function updateUserRole(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateUserRoleInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateUserMsgRole(params) {
  return request(`/hr-ssc/api/api-admin/noticeRole/saveOrUpdateNoticeUserRole`, {
    method: 'post',
    data: params,
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function addRoleInterface(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/saveRoleInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteUserRole(roleId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/dateleRoleInterface?roleId=${roleId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function getMenuEntityList(type) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/queryMenuEntityListInterface?type=${type}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getRoleMenu(roleId,type) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/getRoleMenuInterface?roleId=${roleId}&type=${type}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function updateRoleMenu(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateRoleMenuInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateRoleFunc(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateRoleAuthorityInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}


export async function getOrgGroupList() {
  return request(`/hr-ssc/api/api-admin/roleAssignment/queryOrgGroupListInterface`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getOrgGroupById(groupId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/getOrgGroupInterface`, {
    method: 'post',
    data: groupId,
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return {};
    }
  });
}

export async function getUserGroupList(userId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/getUserGroupListInterface?userId=${userId}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function addUserGroup(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/saveOrgGroupInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateUserGroup(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateUserGroupInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateOrgGroup(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateOrgGroupInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteOrgGroup(groupId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/deleteOrgGroupInterface?groupId=${groupId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function addMenuInterface(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/saveMenuInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateMenuInterface(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateMenuInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteMenu(menuId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/deleteMenuInterface?menuId=${menuId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function getBpmUserByCode(codes) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/getBpmUserByCode`, {
    method: 'get',
    params:codes
  }).then((res) => {
      return res;
  });
}

export async function deleteUserById(userId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/deleteUserById?userId=${userId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}


export async function updateUserStatus(userId,status) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateUserStatus`, {
    method: 'get',
    params:{userId,status}
  }).then((res) => {
    return res;
  });
}

export async function updateUserPassword(id) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/updateUserPassword`, {
    method: 'post',
    data: {id},
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function getContractSubjectList() {
  return request('/hr-ssc/api/api-admin/eSign/getCompanyList', {
    method: 'post',
  }).then((res) => {
    return res.data;
  });
}

export async function getContractAllMainIds() {
  return request('/hr-ssc/api/api-admin/roleAssignment/getContractAllMainIds', {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getAllsalaryGroup() {
  return request('/hr-ssc/api/api-admin/salary/findAllsalaryGroup', {
    method: 'get',
  }).then(( res) => {
    return res.data;
  });
}

export async function saveAndEditContractGroup(params) {
  return request(`/hr-ssc/api/api-admin/contractGroup/saveContractGroup`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function queryContractGroupPage(params) {
  return request('/hr-ssc/api/api-admin/contractGroup/queryContractGroupPage', {
    method: 'get',
    params: {
      ...params,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function deleteContractGroup(id) {
  return request(`/hr-ssc/api/api-admin/contractGroup/deleteContractGroup?id=${id}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function queryContractSubGroupPage(id) {
  return request(`/hr-ssc/api/api-admin/contractGroup/queryContractSubGroupPage`, {
    method: 'get',
    params: {
      id:id
    },
  }).then((res) => {
    return res.data;
  });
}

export async function getContractMainIds(userId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/getContractMainIds`, {
    method: 'get',
    params: {
      userId:userId
    },
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function saveContratctUser(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/saveContratctUser`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function getSalaryByUserId(userId) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/getSalaryByUserId`, {
    method: 'get',
    params: {
      userId:userId
    },
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function saveSalaryUser(params) {
  return request(`/hr-ssc/api/api-admin/roleAssignment/saveSalaryUser`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}
